//package com.jh.paymentchannel.business.impl;
//
//import com.google.common.collect.ImmutableList;
//import com.jh.paymentchannel.business.ChannelBusiness;
//import com.jh.paymentchannel.payment.PaymentException;
//import com.jh.paymentchannel.pojo.freeQuick.*;
//import com.jh.paymentchannel.repository.freeQuick.PaymentChannelRepository;
//import com.jh.paymentchannel.repository.freeQuick.PaymentChannelRouteRepository;
//import com.jh.paymentchannel.repository.freeQuick.RealChannelRepository;
//import com.jh.paymentchannel.repository.freeQuick.SettlementObjectRepository;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.domain.Page;
//import org.springframework.data.domain.Pageable;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.util.List;
//
//
//@Service("channelBusiness")
//public class ChannelBusinessImpl implements ChannelBusiness {
//
//    private final PaymentChannelRepository paymentChannelRepository;
//    private final PaymentChannelRouteRepository paymentChannelRouteRepository;
//    private final RealChannelRepository realChannelRepository;
//    private final SettlementObjectRepository settlementObjectRepository;
//
//    @Autowired
//    public ChannelBusinessImpl(
//            PaymentChannelRepository paymentChannelRepository,
//            PaymentChannelRouteRepository paymentChannelRouteRepository,
//            RealChannelRepository realChannelRepository,
//            SettlementObjectRepository settlementObjectRepository) {
//        this.paymentChannelRepository = paymentChannelRepository;
//        this.paymentChannelRouteRepository = paymentChannelRouteRepository;
//        this.realChannelRepository = realChannelRepository;
//        this.settlementObjectRepository = settlementObjectRepository;
//    }
//
//    @Transactional
//    @Override
//    public PaymentChannel createPaymentChannel(PaymentChannel channel) {
//        return paymentChannelRepository.saveAndFlush(channel);
//    }
//
//    @Transactional
//    @Override
//    public PaymentChannel editPaymentChannel(PaymentChannelDTO channelDTO) throws PaymentException {
//        PaymentChannel paymentChannel = paymentChannelRepository.findByChannelCode(channelDTO.getChannelCode());
//        if (paymentChannel == null) {
//            paymentChannel = PaymentChannel.init(channelDTO);
//        } else {
//            paymentChannel.transform(channelDTO);
//        }
//        paymentChannelRepository.saveAndFlush(paymentChannel);
//        return paymentChannel;
//    }
//
//
//    @Override
//    public List<PaymentChannel> queryAllPaymentChannels() {
//        return paymentChannelRepository.findAll();
//    }
//
//    @Override
//    public List<PaymentChannel> queryAllPaymentChannels(String channelCode, String channelType) {
//        List<PaymentChannel> pcs;
//        if (channelCode != null) {
//            PaymentChannel pc = paymentChannelRepository.findByChannelCode(channelCode);
//            if (pc == null) pcs = ImmutableList.of();
//            else {
//                pcs = ImmutableList.of(pc);
//            }
//        } else if (channelType != null) {
//            pcs = paymentChannelRepository.findByRealPayType(channelType);
//        } else {
//            pcs = paymentChannelRepository.findAll();
//        }
//
//        return pcs;
//    }
//
//    @Override
//    public PaymentChannel queryPaymentChannelByChannelCode(String channelCode) {
//        return paymentChannelRepository.findByChannelCode(channelCode);
//    }
//
//    @Transactional
//    @Override
//    public void delPaymentChannelByChannelcode(String channelcode) {
//        paymentChannelRepository.deleteByChannelCode(channelcode);
//    }
//
//
//    @Override
//    public List<PaymentChannelRoute> queryPaymentChannelRouteByChannelCode(String merchantId, String channelCode) {
//        return paymentChannelRouteRepository.findPaymentChannelRouteByCode(merchantId, channelCode);
//    }
//
//
//    @Override
//    public RealChannel queryRealChannel(String realChannelCode) {
//        List<RealChannel> list = realChannelRepository.findByRealChannelCode(realChannelCode);
//        return list.isEmpty() ? null : list.get(0);
//    }
//
//
//    @Transactional
//    @Override
//    public RealChannel saveRealChannel(RealChannel realChannel) {
//
//        return realChannelRepository.saveAndFlush(realChannel);
//    }
//
//
//    @Transactional
//    @Override
//    public void delRealChannel(String realchannelcode) {
//        realChannelRepository.deleteByRealChannelCode(realchannelcode);
//    }
//
//
//    @Override
//    public List<RealChannel> queryAllRealchannels() {
//
//        return realChannelRepository.findAll();
//    }
//
//    @Override
//    public List<RealChannel> queryAllPCPaymentRealChannels(String realChannelCode, String channelType) {
//        List<RealChannel> realChannels;
//        if (realChannelCode != null
//                && realChannelCode.trim().length() > 0
//                && channelType != null
//                && channelType.trim().length() > 0) {
//            realChannels = realChannelRepository.findByRealChannelCodeAndRealPayType(realChannelCode, channelType);
//        } else if (realChannelCode != null
//                && realChannelCode.trim().length() > 0) {
//            realChannels = realChannelRepository.findByRealChannelCode(realChannelCode);
//        } else if (channelType != null
//                && channelType.trim().length() > 0) {
//            realChannels = realChannelRepository.findEnabledByRealPayType(channelType);
//        } else {
//            realChannels = realChannelRepository.findAll();
//
//        }
//
//        return realChannels;
//    }
//
//    @Transactional
//    @Override
//    public PaymentChannelRoute createPaymentChannelRoute(PaymentChannelRoute route) {
//
//        return paymentChannelRouteRepository.saveAndFlush(route);
//    }
//
//    @Transactional
//    @Override
//    public void delPaymentChannelRoute(long id) {
//        paymentChannelRouteRepository.delPaymentChannelRouteById(id);
//    }
//
//
//    @Override
//    public Page<PaymentChannelRoute> pagePaymentChannelRoute(String merchantId, Pageable pageable) {
//
//        if (merchantId != null && !merchantId.equalsIgnoreCase("")) {
//
//            return paymentChannelRouteRepository.findPaymentChannelRouteByMerchantid(merchantId, pageable);
//
//        } else {
//
//            return paymentChannelRouteRepository.findPaymentChannelRoute(pageable);
//
//        }
//
//    }
//
//
//    @Override
//    public List<SettlementObject> queryAllSettlementObject() {
//
//        return settlementObjectRepository.findAll();
//
//    }
//
//
//    @Transactional
//    @Override
//    public SettlementObject addNewSettlementObject(SettlementObject settlementObject) {
//        return settlementObjectRepository.saveAndFlush(settlementObject);
//    }
//
//    @Transactional
//    @Override
//    public void delSettlementObject(String settlementid) {
//        settlementObjectRepository.deleteBySettlementId(settlementid);
//    }
//
//    @Transactional
//    @Override
//    public void updateChannelRouteStatus(String realchannelcode, String status) {
//        paymentChannelRouteRepository.updateChannelRouteStatus(status, realchannelcode);
//    }
//
//
//    @Override
//    public List<RealChannel> queryRealChannelsByType(String realPayType) {
//
//        return realChannelRepository.findAllByRealPayType(realPayType);
//    }
//
//
//}
